﻿using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zhy.PrismRegion.Journal.ViewModels.Pages
{
    public class ViewAViewModel :
        INavigationAware // 接收导航参传递接口
    {
        /// <summary>
        /// 后退
        /// </summary>
        public DelegateCommand GoBackCommand { get; set; }
        /// <summary>
        /// 前进
        /// </summary>
        public DelegateCommand ForwordCommand { get; set; }

        /// <summary>
        /// 历史记录接口
        /// </summary>
        IRegionNavigationJournal journal;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="regionManager">区域子页面管理接口注入</param>
        public ViewAViewModel(IRegionManager regionManager)
        {
            GoBackCommand = new DelegateCommand(() =>  // 后退按钮
            {
                if (journal.CanGoBack) // 判断是否有可执行的后退步骤
                {
                    journal.GoBack(); // 执行后退步骤
                }
            });
            ForwordCommand = new DelegateCommand(() => // 前进按钮
            {
                if (journal.CanGoForward) // 判断是否有可前进的执行步骤
                {
                    journal.GoForward(); // 执行前进步骤
                }
                else
                {
                    regionManager.RequestNavigate("MainRegion", "ViewB"); // 打开下一页面
                }
            });
        }


        /// <summary>
        /// 打开当前View的时候触发
        /// </summary>
        /// <param name="navigationContext">数据上下文</param>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            journal = navigationContext.NavigationService.Journal;  // 获取历史记录
        }

        /// <summary>
        /// 是否允许重复导航进来
        /// </summary>
        /// <param name="navigationContext">数据上下文</param>
        /// <returns></returns>
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        /// <summary>
        /// 从当前View导航出去的时候触发
        /// </summary>
        /// <param name="navigationContext">数据上下文</param>
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }
    }
}
